//
//  DataCensusVC.m
//  New_Runway
//
//  Created by mack on 2018/2/7.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "DataCensusVC.h"
#import "DataCensusCell.h"
#import "DataHeaderView.h"
#import "BasePickView.h"
#import "PickDateView.h"
#import "ShopModel.h"
#import "PickCustomView.h"
#import "DataModel.h"
#import "DayDataModel.h"
#import "DataDetailVCViewController.h"
#import "DataDaySalceModel.h"
@interface DataCensusVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,PickerDateViewDelegate,CustomPickViewDelegate>
@property (nonatomic, strong) NSMutableArray *controllers;
@property (nonatomic, strong) UICollectionView *collectionview;
@property (nonatomic, assign) CGRect rect;
@property (nonatomic, assign) BOOL isShowDay;
@property (nonatomic, copy) NSString *dateStr;
@property (nonatomic, strong) NSMutableArray *shopArray;
@property (nonatomic, assign) NSInteger currentTime;
@property (nonatomic, assign) NSInteger currentTimeT;
@property (nonatomic, assign) NSInteger currentTimeTS;
@property (nonatomic, copy) NSString *shopId;
@property (nonatomic, copy) NSString *shopName;
@property (nonatomic, strong) DataModel *dataModel;
@property (nonatomic, strong)DayDataModel *dayModel;
@property (nonatomic, strong) DataDaySalceModel *daySalceModel;
@end

@implementation DataCensusVC

-(NSMutableArray *)shopArray{
    
    if (!_shopArray) {
        _shopArray = [[NSMutableArray alloc] init];
    }
    return _shopArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationBarView.titleLabel.text = @"数据统计";
    self.navigationBarView.backgroundColor = UIColorHex(0xf56e6d);
    self.navigationBarView.lineView.hidden = YES;
    self.view.backgroundColor = kColorWhite();
    
    self.shopId = [NRWCarUser sharedUser].shopId ? [NRWCarUser sharedUser].shopId : @"";
    self.currentTime = [NRWCarTurnTime getNowTimestamp] * 1000;
    NSString *currstr = [NRWCarTurnTime timestampSwitchTime:self.currentTime andFormatter:@"yyyy-MM"];
    self.currentTime = [NRWCarTurnTime timeSwitchTimestamp:currstr andFormatter:@"yyyy-MM"] * 1000;
    self.currentTimeTS = self.currentTimeT = [NRWCarTurnTime getNowTimestamp] * 1000;
    self.shopName = @"车商";
    [self creatCollectionView];
    [self loadData];
    [self loadDayData];
    if ([NRWCarUser sharedUser].shopId) {
        [self loadDaySalceData];
    }
}
-(void)creatCollectionView{
    _rect = CGRectMake(0, 0, Screen_width, Screen_height);
    CGFloat realWi = [self fixSlitWith:_rect colCount:4 space:0];

    //创建一个layout布局类
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    //设置布局方向为垂直流布局
    layout.itemSize = CGSizeMake(realWi, 130);
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.minimumLineSpacing      = 0;
    layout.minimumInteritemSpacing = 0;
    //创建collectionView 通过一个布局策略layout来创建
    _collectionview = [[UICollectionView alloc]initWithFrame:CGRectMake(0, self.navH, _rect.size.width, _rect.size.height - self.navH - self.BotH) collectionViewLayout:layout];
    //代理设置
    _collectionview.backgroundColor = UIColorHex(0xf5f5f5);
    _collectionview.delegate=self;
    _collectionview.dataSource=self;
    //注册item类型 这里使用系统的类型
    [_collectionview registerNib:[UINib nibWithNibName:@"DataCensusCell" bundle:nil] forCellWithReuseIdentifier:@"DataCensusCell"];
    
    
    [_collectionview registerNib:[UINib nibWithNibName:@"DataHeaderView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DataHeaderView"];
     [_collectionview registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"header"];
    
    [self.view addSubview:_collectionview];
    
    
    
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    if ([NRWCarUser sharedUser].shopId) {
        return 3;
    }
    return 2;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    return 4;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSArray *array = @[@"入库累计",@"出库累计",@"当月库存",@"当前在库"];
    NSArray *arrayT = @[@"已入库",@"已出库",@"已预定",@""];
    NSArray *arrayS = @[@"已跟进",@"已预约",@"已成交",@""];

    DataCensusCell * cell  = [collectionView dequeueReusableCellWithReuseIdentifier:@"DataCensusCell" forIndexPath:indexPath];
    if (indexPath.section == 0) {
        cell.backgroundColor = UIColorHex(0xf56e6d);
        [cell.iconImage setImage:[UIImage imageNamed:array[indexPath.row]]];
        cell.titleL.text = array[indexPath.row];
        cell.titleL.textColor = kColorWhite();
        cell.numL.textColor = kColorWhite();
        cell.dicance.constant = 20;
        if (indexPath.row == 0) {
            cell.numL.text = _dataModel.result.thisMonthStorageInfo.storageNum;
        }else if (indexPath.row == 1){
            cell.numL.text = _dataModel.result.totalOutStorageInfo.storageNum;

        }else if (indexPath.row == 2){
            cell.numL.text = _dataModel.result.totalStorageInfo.storageNum;

        }else if (indexPath.row == 3){
            cell.numL.text = _dataModel.result.currentStorageInfo.storageNum;

        }
    }else if (indexPath.section == 1){
        cell.backgroundColor = kColorWhite();
        [cell.iconImage setImage:[UIImage imageNamed:arrayT[indexPath.row]]];
        cell.titleL.text = arrayT[indexPath.row];
        cell.titleL.textColor = MAIN_FONT_COLOR();
        cell.numL.textColor = MAIN_FONT_COLOR();
        cell.dicance.constant = 10;
        if (indexPath.row == 0) {
             cell.numL.text = _dayModel.result.storageInfo.storageNum;
        }else if (indexPath.row == 1){
            cell.numL.text = _dayModel.result.outStorageInfo.storageNum;

        }else if (indexPath.row == 2){
            cell.numL.text = _dayModel.result.carOrderInfo.storageNum;
            
        }else{
            cell.numL.text = @"";

        }

    }else if (indexPath.section == 2){
        cell.dicance.constant = 10;
        cell.backgroundColor = kColorWhite();
        [cell.iconImage setImage:[UIImage imageNamed:arrayS[indexPath.row]]];
        cell.titleL.text = arrayS[indexPath.row];
        cell.titleL.textColor = MAIN_FONT_COLOR();
        cell.numL.textColor = MAIN_FONT_COLOR();
        if (indexPath.row == 0) {
            cell.numL.text = _daySalceModel.result.followUpInfo.followUpNum;
        }else if (indexPath.row == 1){
            cell.numL.text = _daySalceModel.result.orderUpInfo.orderUpNum;
            
        }else if (indexPath.row == 2){
            cell.numL.text = _daySalceModel.result.fixtureUpInfo.fixtureUpNum;
            
        }else{
            cell.numL.text = @"";
            
        }
    }
    
    return cell;
}


-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView
                       layout:(UICollectionViewLayout *)collectionViewLayout
       insetForSectionAtIndex:(NSInteger)section

{
    return UIEdgeInsetsMake(0, 0, 0, 0);//分别为上、左、下、右

}
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    if (kind == UICollectionElementKindSectionHeader) {
        kSelfWeak;
        DataHeaderView *headerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"DataHeaderView" forIndexPath:indexPath];
        if (indexPath.section == 0) {
            headerview.backgroundColor = UIColorHex(0xf56e6d);
            headerview.bottomView.hidden = YES;
            [headerview.firstBtn setTitle:[NRWCarTurnTime timestampSwitchTime:self.currentTime andFormatter:@"YYYY-MM"] forState:UIControlStateNormal];
            [headerview.firstBtn setTitleColor:kColorWhite() forState:UIControlStateNormal];
            [headerview.firstBtn setImage:[UIImage imageNamed:@"日历"] forState:UIControlStateNormal];
            [headerview.lastBtn setTitle:self.shopName forState:UIControlStateNormal];
            [headerview.lastBtn setTitleColor:kColorWhite() forState:UIControlStateNormal];
            if ([NRWCarUser sharedUser].shopId) {
                headerview.lastBtn.hidden = YES;
            }else{
                headerview.lastBtn.hidden = NO;
            }
            headerview.clickBlock = ^(NSInteger index) {
                if (index == 1) {
                    weakSelf.isShowDay = NO;
                    [weakSelf CreatDateChoose:1];
                }else{
                    [weakSelf loadShopList];
                }
            };
        }else if(indexPath.section == 1) {

            headerview.backgroundColor = kColorWhite();
            headerview.bottomView.hidden = NO;
            [headerview.firstBtn setTitle:@"  日库存小计" forState:UIControlStateNormal];
            [headerview.firstBtn setTitleColor:MAIN_FONT_COLOR() forState:UIControlStateNormal];
            [headerview.firstBtn setImage:[UIImage imageNamed:@"dataH"] forState:UIControlStateNormal];
            [headerview.lastBtn setTitleColor:UIColorHex(0x989898) forState:UIControlStateNormal];
            headerview.lastBtn.hidden = NO;
            [headerview.lastBtn setTitle:[NRWCarTurnTime timestampSwitchTime:self.currentTimeT andFormatter:@"yyyy-MM-dd"] forState:UIControlStateNormal];
            headerview.clickBlock = ^(NSInteger index) {
                if (index == 2) {
                    weakSelf.isShowDay = YES;
                    [weakSelf CreatDateChoose:2];
                }
                
            };
            
        }else if (indexPath.section == 2){
            headerview.backgroundColor = kColorWhite();
            headerview.bottomView.hidden = NO;
            [headerview.firstBtn setTitle:@"  日销售小计" forState:UIControlStateNormal];
            [headerview.firstBtn setTitleColor:MAIN_FONT_COLOR() forState:UIControlStateNormal];
            [headerview.firstBtn setImage:[UIImage imageNamed:@"日销售小计"] forState:UIControlStateNormal];
            [headerview.lastBtn setTitleColor:UIColorHex(0x989898) forState:UIControlStateNormal];
            headerview.lastBtn.hidden = NO;
            [headerview.lastBtn setTitle:[NRWCarTurnTime timestampSwitchTime:self.currentTimeTS andFormatter:@"yyyy-MM-dd"] forState:UIControlStateNormal];
            headerview.clickBlock = ^(NSInteger index) {
                if (index == 2) {
                    weakSelf.isShowDay = YES;
                    [weakSelf CreatDateChoose:3];
                }
                
            };
        }
        
        return headerview;
    }
    UICollectionReusableView *footerView =  [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"header" forIndexPath:indexPath];
    return footerView;


}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

    return CGSizeMake(Screen_width, 40);
}
-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section{
    return CGSizeMake(Screen_width, 10);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    DataDetailVCViewController *detailVC = [[DataDetailVCViewController alloc] init];
    detailVC.shopID = self.shopId;
    if (indexPath.section == 0) {
        detailVC.currentTime = self.currentTime;
 
        if (indexPath.row == 0) {
            detailVC.mainTitle = @"入库累计";
            detailVC.statisType = @"1";
            if ([_dataModel.result.thisMonthStorageInfo.storageNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据" duration:2.0 withRemindId:remindWarning];

                 return;
            }
        }else if (indexPath.row == 1){
            detailVC.mainTitle = @"出库累计";
            detailVC.statisType = @"2";
            if ([_dataModel.result.totalOutStorageInfo.storageNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];

                 return;
            }
        }else if (indexPath.row == 2){
            detailVC.mainTitle = @"当月库存";
            detailVC.statisType = @"3";
            if ([_dataModel.result.totalStorageInfo.storageNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];

                return;
            }
        }else if (indexPath.row == 3){
            detailVC.mainTitle = @"当前在库";
            detailVC.statisType = @"4";
            if ([_dataModel.result.currentStorageInfo.storageNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];
                 return;
            }
        }
        detailVC.isSale = NO;
        detailVC.isDay = NO;
    }else if (indexPath.section == 1){
        detailVC.currentTime = self.currentTimeT;

        if (indexPath.row == 0) {
            detailVC.mainTitle = @"已入库";
            detailVC.statisType = @"1";
            if ([_dayModel.result.storageInfo.storageNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];
                 return;
            }

        }else if (indexPath.row == 1){
            detailVC.mainTitle = @"已出库";
            detailVC.statisType = @"2";
            if ([_dayModel.result.outStorageInfo.storageNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];
                 return;
            }
        }else if (indexPath.row == 2){
            detailVC.mainTitle = @"已预定";
            detailVC.statisType = @"5";
            if ([_dayModel.result.carOrderInfo.storageNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];
                return;
            }

        }else if (indexPath.row == 3){
            return;
        }
        detailVC.isSale = NO;
        detailVC.isDay = YES;

    }else if (indexPath.section == 2){
        
        detailVC.currentTime = self.currentTimeTS;
        
        if (indexPath.row == 0) {
            detailVC.mainTitle = @"已跟进";
            detailVC.followState = 10;
            detailVC.searchType = @"followUpInfo";
            detailVC.crmTotalNum = [_daySalceModel.result.followUpInfo.followUpNum integerValue];
            if ([_daySalceModel.result.followUpInfo.followUpNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];
                return;
            }
            
        }else if (indexPath.row == 1){
            detailVC.mainTitle = @"已预约";
            detailVC.followState = 20;
            detailVC.searchType = @"orderUpInfo";
            detailVC.crmTotalNum = [_daySalceModel.result.orderUpInfo.orderUpNum integerValue];
            if ([_daySalceModel.result.orderUpInfo.orderUpNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];
                return;
            }
        }else if (indexPath.row == 2){
            detailVC.mainTitle = @"已成交";
            detailVC.searchType = @"fixtureInfo";
            detailVC.followState = 50;
            detailVC.crmTotalNum = [_daySalceModel.result.fixtureUpInfo.fixtureUpNum integerValue];
            if ([_daySalceModel.result.fixtureUpInfo.fixtureUpNum isEqualToString:@"0"]) {
                [ShowMessage showHintMessage:@"暂无数据!" duration:2.0 withRemindId:remindWarning];
                return;
            }
            
        }else if (indexPath.row == 3){
            return;
        }
        detailVC.isSale = YES;
        detailVC.isDay = YES;
    }
    
    [self.navigationController pushViewController:detailVC animated:YES];
}

- (CGFloat)fixSlitWith:(CGRect)rect colCount:(CGFloat)colCount space:(CGFloat)space {
    CGFloat totalSpace = (colCount - 1) * space;//总共留出的距离
    CGFloat itemWidth = (rect.size.width - totalSpace) / colCount;// 按照真实屏幕算出的cell宽度 （iPhone6 375*667）93.75
    CGFloat fixValue = 1 / [UIScreen mainScreen].scale; //(1px=0.5pt,6Plus为3px=1pt)
    CGFloat realItemWidth = floor(itemWidth) + fixValue;//取整加fixValue  floor:如果参数是小数，则求最大的整数但不大于本身.
    if (realItemWidth < itemWidth) {// 有可能原cell宽度小数点后一位大于0.5
        realItemWidth += fixValue;
    }
    CGFloat realWidth = colCount * realItemWidth + totalSpace;//算出屏幕等分后满足1px=([UIScreen mainScreen].scale)pt实际的宽度,可能会超出屏幕,需要调整一下frame
    CGFloat pointX = (realWidth - rect.size.width) / 2; //偏移距离
    rect.origin.x = -pointX;//向左偏移
    rect.size.width = realWidth;
    _rect = rect;
    return realItemWidth; //每个cell的真实宽度
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

//时间
-(void)CreatDateChoose:(NSInteger)tag{
    
    PickDateView *pickerDate = [[PickDateView alloc]init];
    pickerDate.tag = tag;
    pickerDate.pickerViewHeight = 300;
//    [pickerDate setIsAddYetSelect:NO];//是否显示至今选项
    [pickerDate setIsShowDay:_isShowDay];//是否显示日信息
    NSCalendar *gregorian = [[NSCalendar alloc]
                             initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    // 获取当前日期
    NSDate* dt = [NSDate date];
    // 指定获取指定年、月、日、时、分、秒的信息
    unsigned unitFlags = NSCalendarUnitYear |
    NSCalendarUnitMonth |  NSCalendarUnitDay |
    NSCalendarUnitHour |  NSCalendarUnitMinute |
    NSCalendarUnitSecond | NSCalendarUnitWeekday;
    NSDateComponents* comp = [gregorian components: unitFlags fromDate:dt];
    [pickerDate setDefaultTSelectYear:comp.year defaultSelectMonth:comp.month defaultSelectDay:comp.day];//设定默认显示的日期
    [pickerDate setDelegate:self];
    [pickerDate show];
}

-(void)pickerDateView:(BasePickView *)pickerDateView selectYear:(NSInteger)year selectMonth:(NSInteger)month selectDay:(NSInteger)day{
  
    if (_isShowDay==YES) {
            _dateStr = [NSString stringWithFormat:@"%ld-%ld-%ld",year,month,day];
        
    }else{
   
            _dateStr = [NSString stringWithFormat:@"%ld-%ld",year,month];
    }
    
    if (pickerDateView.tag == 1) {
        self.currentTime = [NRWCarTurnTime timeSwitchTimestamp:_dateStr andFormatter:@"yyyy-MM"] * 1000;
        [self loadData];
    }else if (pickerDateView.tag == 2){
        self.currentTimeT = [NRWCarTurnTime timeSwitchTimestamp:_dateStr andFormatter:@"yyyy-MM-dd"] * 1000;
        [self loadDayData];

    }else if (pickerDateView.tag == 3){
        self.currentTimeTS = [NRWCarTurnTime timeSwitchTimestamp:_dateStr andFormatter:@"yyyy-MM-dd"] * 1000;
        [self loadDaySalceData];

    }
    
    
}
//商铺
-(void)loadShopList{
    NSString *url = [NSString stringWithFormat:@"%@%@",Api,shopListApi];
    
    NSDictionary *params = @{
                             @"marketId":[NRWCarUser sharedUser].marketId,
                              @"shopState":@1
                             };
    [YQNetworking postWithUrl:url refreshRequest:YES cache:NO params:params progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        
        ShopModel *model = [ShopModel mj_objectWithKeyValues:response];
        if (model.code == 1) {
            [self.shopArray removeAllObjects];
            NSMutableArray *shopNames = [[NSMutableArray alloc] init];
            for (NSDictionary *dic in model.result) {
                shopResult *model = [shopResult mj_objectWithKeyValues:dic];
                [self.shopArray addObject:model];
                [shopNames addObject:model.shopName];
            }
            
            [self creatChoose:shopNames tag:1];
            
        }
        
        
        
    } failBlock:^(NSError *error) {
        [ShowMessage showHintMessage:@"请求失败!" duration:2.0 withRemindId:remindFail];
    }];
    
    
}
//单个信息
-(void)creatChoose:(NSMutableArray *)titles tag:(NSInteger)tag{
    
    
    PickCustomView *pickerSingle = [[PickCustomView alloc]init];
    pickerSingle.tag = tag;
    
    pickerSingle.pickerViewHeight = 300;
    [pickerSingle setDataArray:titles];
    [pickerSingle setDefalutSelectRowStr:titles[0]];
    [pickerSingle setDelegate:self];
    [pickerSingle show];
    [self.view endEditing:YES];
}
-(void)customPickView:(PickCustomView *)customPickView selectedTitle:(NSString *)selectedTitle index:(NSInteger)index{
    self.shopName = selectedTitle;
    shopResult *model = self.shopArray[index];
    self.shopId = model.shopId;
    [self loadData];
    [self loadDayData];
    
    
}
-(void)loadData{
    
    NSString *url = [NSString stringWithFormat:@"%@%@",Api,DataApi];
    NSDictionary *params = @{
                             @"marketId":[NRWCarUser sharedUser].marketId,
                             @"month":[NRWCarTurnTime timestampSwitchTime:self.currentTime andFormatter:@"yyyy-MM"],
                             @"shopId":self.shopId
                             
                             };
    [YQNetworking postWithUrl:url refreshRequest:YES cache:NO params:params progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        _dataModel = [DataModel mj_objectWithKeyValues:response];
        [UIView animateWithDuration:0 animations:^{
            [self.collectionview performBatchUpdates:^{
                [self.collectionview reloadSections:[NSIndexSet indexSetWithIndex:0]];
            } completion:nil];
        }];
  
    } failBlock:^(NSError *error) {
        [ShowMessage showHintMessage:@"请求失败!" duration:2.0 withRemindId:remindFail];
    }];
}

-(void)loadDayData{
    
    NSString *url = [NSString stringWithFormat:@"%@%@",Api,DayDataApi];
    NSDictionary *params = @{
                             @"marketId":[NRWCarUser sharedUser].marketId,
                             @"startDate":[NRWCarTurnTime timestampSwitchTime:self.currentTimeT andFormatter:@"yyyy-MM-dd"],
                             @"shopId":self.shopId
                             };
    [YQNetworking postWithUrl:url refreshRequest:YES cache:NO params:params progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
    
        _dayModel = [DayDataModel mj_objectWithKeyValues:response];
   
        [UIView animateWithDuration:0 animations:^{
            [self.collectionview performBatchUpdates:^{
                [self.collectionview reloadSections:[NSIndexSet indexSetWithIndex:1]];
            } completion:nil];
        }];

    } failBlock:^(NSError *error) {
        [ShowMessage showHintMessage:@"请求失败!" duration:2.0 withRemindId:remindFail];
    }];

}

-(void)loadDaySalceData{
    
    NSString *url = [NSString stringWithFormat:@"%@%@",CRMContextApi,DaySalceApi];
    NSDictionary *params = @{
                             @"marketId":[NRWCarUser sharedUser].marketId,
                             @"queryDate":[NRWCarTurnTime timestampSwitchTime:self.currentTimeTS andFormatter:@"yyyy-MM-dd"],
                             @"shopId":self.shopId
                             };
    [YQNetworking postWithUrl:url refreshRequest:YES cache:NO params:params progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        
        _daySalceModel = [DataDaySalceModel mj_objectWithKeyValues:response];
        
        [UIView animateWithDuration:0 animations:^{
            [self.collectionview performBatchUpdates:^{
                [self.collectionview reloadSections:[NSIndexSet indexSetWithIndex:2]];
            } completion:nil];
        }];
        
    } failBlock:^(NSError *error) {
        [ShowMessage showHintMessage:@"请求失败!" duration:2.0 withRemindId:remindFail];
    }];

}
@end
